package org.apache.cordova.notify;
import java.util.TimeZone;

import org.apache.cordova.CordovaWebView;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaInterface;
import org.json.JSONArray;
import org.json.JSONException;




import cn.clickmed.DaTong.R;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;


public class notification extends CordovaPlugin {  
    @SuppressWarnings("deprecation")
	@Override  
    public boolean execute(String action, JSONArray args,  
            CallbackContext callbackContext) throws JSONException {  
        if ("send".equals(action)) {  
            NotificationManager manager = (NotificationManager) this.cordova  
                    .getActivity().getSystemService(  
                            Context.NOTIFICATION_SERVICE);  
  
            String title = args.getString(0);
            String text = args.getString(1);
            System.out.println("��Ҫ���͵���Ϣ..." + text);

            Notification.Builder builder = new Notification.Builder(this.cordova.getActivity());
            builder.setSmallIcon(R.drawable.datong_ic_launcher);
            builder.setTicker(text);
            builder.setWhen(System.currentTimeMillis());
            builder.setAutoCancel(true);
            builder.setDefaults(Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE);
            this.cordova.getActivity().getIntent().putExtra("name",text);
            this.cordova.getActivity().getIntent().putExtra("title",title);

            builder.setContentTitle(title);
            builder.setContentIntent(PendingIntent.getActivity(this.cordova.getActivity(),
                    1, this.cordova.getActivity().getIntent().putExtra("isRead",
                            String.valueOf( System.currentTimeMillis()))
                    , 0));
            builder.setContentText(text);
            builder.setDeleteIntent(null);

            manager.notify(1, builder.build());
     //       callbackContext.success(text);
            return true;
        } else {  
            return false;  
        }  
    }  
} 